﻿package core {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	public class Canvas extends Sprite {
		
		private var _width:Number;
		private var _height:Number;
		
		public function Canvas():void {
			this._width = this._height = 0;
			addEventListener(Event.RESIZE, _resize);
		}
		///override this in all subclasses to know when it's resized.
		public function resize():void { }
		///only call resize() if currentTarget == target
		private function _resize(e:Event):void {
			if (e.target == e.currentTarget)
				resize();
		}
		
		public final override function get width():Number { return this._width; }
		public final override function set width(n:Number):void {
			this._width = n;
			this.dispatchEvent(new Event(Event.RESIZE, true, true));
		}
		public final override function get height():Number { return this._height; }
		public final override function set height(n:Number):void {
			this._height = n;
			this.dispatchEvent(new Event(Event.RESIZE, true, true));
		}
		public final function get rect():Rectangle { return new Rectangle(this.x, this.y, this.width, this.height); }
		public final function set rect(r:Rectangle):void {
			this.x = r.x;
			this.y = r.y;
			this._width = r.width;
			this._height = r.height;
			dispatchEvent(new Event(Event.RESIZE, true, true));
		}
	}
	
	
}